package com.txt;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.txt.constant.CacheConstant;
import com.txt.domain.Book;
import com.txt.service.BookService;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

import java.text.MessageFormat;
import java.util.concurrent.TimeUnit;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(SpringRunner.class)
class T1 {
    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    BookService bookService;


    @Test
    void redisTest() {
        //生产者消费者测试
        redisTemplate.convertAndSend(CacheConstant.TOPIC_TEST, "value");
        //key的过期监听
        redisTemplate.opsForValue().set("testKey", "", 1, TimeUnit.SECONDS);
        try {
            Thread.sleep(1500);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }


    @Test
    void mybatisPlusTest() {
        //分页查
        Page<Book> page = bookService.page(Page.of(1, 10),
                Wrappers.lambdaQuery(Book.class).eq(Book::getId, 1));
        page.getRecords().forEach(System.out::println);
        System.out.println(MessageFormat.format("总页数：{0}", page.getPages()));
    }

}

